package org.harsh.transmission.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.harsh.transmission.domain.TransReceiver;
import org.harsh.transmission.service.ITransReceiverService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息接收对象Controller
 * 
 * @author liuhaibo
 * @date 2024-08-25
 */
@Controller
@RequestMapping("/transmission/receiver")
public class TransReceiverController extends BaseController
{
    private String prefix = "transmission/receiver";

    @Autowired
    private ITransReceiverService transReceiverService;

    @RequiresPermissions("transmission:receiver:view")
    @GetMapping()
    public String receiver()
    {
        return prefix + "/receiver";
    }

    /**
     * 查询消息接收对象列表
     */
    @RequiresPermissions("transmission:receiver:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TransReceiver transReceiver)
    {
        startPage();
        List<TransReceiver> list = transReceiverService.selectTransReceiverList(transReceiver);
        return getDataTable(list);
    }

    /**
     * 导出消息接收对象列表
     */
    @RequiresPermissions("transmission:receiver:export")
    @Log(title = "消息接收对象", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TransReceiver transReceiver)
    {
        List<TransReceiver> list = transReceiverService.selectTransReceiverList(transReceiver);
        ExcelUtil<TransReceiver> util = new ExcelUtil<TransReceiver>(TransReceiver.class);
        return util.exportExcel(list, "消息接收对象数据");
    }

    /**
     * 新增消息接收对象
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存消息接收对象
     */
    @RequiresPermissions("transmission:receiver:add")
    @Log(title = "消息接收对象", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TransReceiver transReceiver)
    {
        return toAjax(transReceiverService.insertTransReceiver(transReceiver));
    }

    /**
     * 修改消息接收对象
     */
    @RequiresPermissions("transmission:receiver:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TransReceiver transReceiver = transReceiverService.selectTransReceiverById(id);
        mmap.put("transReceiver", transReceiver);
        return prefix + "/edit";
    }

    /**
     * 修改保存消息接收对象
     */
    @RequiresPermissions("transmission:receiver:edit")
    @Log(title = "消息接收对象", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TransReceiver transReceiver)
    {
        return toAjax(transReceiverService.updateTransReceiver(transReceiver));
    }

    /**
     * 删除消息接收对象
     */
    @RequiresPermissions("transmission:receiver:remove")
    @Log(title = "消息接收对象", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(transReceiverService.deleteTransReceiverByIds(ids));
    }
}
